package com.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.Common;
import com.common.ReturnCode;
import com.dao.SysAddressLimitDao;
import com.dao.SysOperateLogDao;
import com.model.ReponseDto;
import com.model.SysAddressLimit;
import com.model.SysOperateLog;
import com.service.ISysAddressLimitService;

@Service
public class SysAddressLimitServiceImpl implements ISysAddressLimitService {

    @Autowired
    private SysAddressLimitDao sysAddressLimitDao;

    @Autowired
    private SysOperateLogDao sysOperateLogDao;

    @Override
    public ReponseDto<List<SysAddressLimit>> list() {

        return new ReponseDto<>(sysAddressLimitDao.get(null));

    }

    @Override
    public ReponseDto<String> edit(Integer id, Integer type, Integer value, String userId, String username) {
        if (null == id || null == type || null == value) {
            return new ReponseDto<>(ReturnCode.PARAM_ERROR);
        }
        Map<String, Object> parMap = new HashMap<>();
        parMap.put("id", id);
        parMap.put("value", value);
        // 开关类型0:充值开关,1:内部转币开关,2:提币开关
        parMap.put("type", type);
        sysAddressLimitDao.update(parMap);

        SysOperateLog sysOperateLog = new SysOperateLog();
        sysOperateLog.setUserId(Long.valueOf(userId));
        sysOperateLog.setUserName(username);
        sysOperateLog.setActiveType(Common.ACTIVE_TYPE_UPDATE);
        sysOperateLog.setDescription("开关管理-编辑开关");
        sysOperateLog.setDataCcope("开关管理-编辑开关");
        sysOperateLogDao.insert(sysOperateLog);

        return new ReponseDto<>();
    }

}
